package com.lp.business.dao;

import java.util.List;

import org.iframework.commons.domain.order.Order;
import org.iframework.commons.domain.pager.Pager;
import org.iframework.commons.util.fast.D;
import org.iframework.commons.util.fast.V;
import org.iframework.support.spring.hibernate.dao.BaseHibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.lp.business.model.Member;

/**
 * 会员
 * 
 * @author maojunjie
 * 
 */
@Repository("memberDao")
public class MemberDao extends BaseHibernateDaoSupport<Member, String> {

	@Override
	public List<Member> findByModel(Member model, Order order, Pager pager) {
		model = model == null ? new Member() : model;
		StringBuilder hql = new StringBuilder();
		hql.append("from Member c where 1=1");
		hql.append(V.isNotEmpty(model.getId()) ? " and c.id=:id " : "");
		hql.append(V.isNotEmpty(model.getUserName()) ? " and c.userName like '%" + model.getUserName() + "%' " : "");
		hql.append(V.isNotEmpty(model.getMobile()) ? " and c.mobile=:mobile " : "");
		hql.append(V.isNotEmpty(model.getLoginName()) ? " and c.loginName=:loginName " : "");
		hql.append(V.isNotEmpty(model.getLoginPwd()) ? " and c.loginPwd=:loginPwd " : "");
		hql.append(V.isNotEmpty(model.getOpenId()) ? " and c.openId=:openId " : "");
		hql.append(V.isNotEmpty(model.getStatus()) ? " and c.status=:status " : "");
		hql.append(V.isNotEmpty(model.getDateStart())
				? " and c.createTime>'" + D.format(model.getDateStart(), "yyyy-MM-dd HH:mm:ss") + "'" : "");
		hql.append(V.isNotEmpty(model.getDateEnd())
				? " and c.createTime<'" + D.format(model.getDateEnd(), "yyyy-MM-dd HH:mm:ss") + "'" : "");

		hql.append(order != null ? order.toString() : "");
		return this.findByQueryString(hql.toString(), model, pager);
	}
}
